<?xml version="1.0" encoding="UTF-8"?>
<definitions id="definitions" 
  xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
  xmlns:camunda="http://camunda.org/schema/1.0/bpmn"
  targetNamespace="Examples">
  
  <process id="transactionProcess" isExecutable="true">

    <startEvent id="start" />
    
    <sequenceFlow sourceRef="start" targetRef="tx" />

    <transaction id="tx">

      <startEvent id="txStart" />
      
      <sequenceFlow sourceRef="txStart" targetRef="fork" />

      <parallelGateway id="fork" />
      
      <sequenceFlow sourceRef="fork" targetRef="bookHotel" />
      <sequenceFlow sourceRef="fork" targetRef="bookFlight" />

      <serviceTask id="bookHotel" camunda:expression="${true}">
        <multiInstanceLoopCharacteristics isSequential="true">
          <loopCardinality>5</loopCardinality>
        </multiInstanceLoopCharacteristics>
      </serviceTask>    
        
      <serviceTask id="bookFlight" camunda:expression="${true}"/>

      <boundaryEvent id="compensateBookHotelEvt" name="Boundary event" attachedToRef="bookHotel">
        <compensateEventDefinition />
      </boundaryEvent>  
        
      <boundaryEvent id="compensateBookFlightEvt" name="Boundary event" attachedToRef="bookFlight">
        <compensateEventDefinition />
      </boundaryEvent>  
      
      <serviceTask id="undoBookHotel" isForCompensation="true" camunda:class="org.camunda.bpm.engine.test.bpmn.event.compensate.helper.WaitStateUndoService">
         <extensionElements>
              <camunda:field name="counterName" stringValue="undoBookHotel" />
         </extensionElements>        
      </serviceTask>
      
      <serviceTask id="undoBookFlight" isForCompensation="true" camunda:class="org.camunda.bpm.engine.test.bpmn.event.compensate.helper.WaitStateUndoService">
         <extensionElements>
              <camunda:field name="counterName" stringValue="undoBookFlight" />
         </extensionElements>        
      </serviceTask>
      
      <sequenceFlow sourceRef="bookHotel" targetRef="receive" />
      
      <receiveTask id="receive" />
      
      <sequenceFlow sourceRef="bookFlight" targetRef="askCustomer" />
      
      <userTask id="askCustomer" camunda:assignee="kermit" />

      <exclusiveGateway id="confirmed" />
      
      <sequenceFlow sourceRef="askCustomer" targetRef="confirmed" />
      
      <sequenceFlow sourceRef="confirmed" targetRef="success">
        <conditionExpression>${confirmed}</conditionExpression>
      </sequenceFlow>
      
      <sequenceFlow sourceRef="confirmed" targetRef="failure">
        <conditionExpression>${not confirmed}</conditionExpression>
      </sequenceFlow>

      <endEvent id="success" />

      <endEvent id="failure" >
        <cancelEventDefinition id="cancelTx" />
      </endEvent>
      
      <association associationDirection="One" id="a1"  sourceRef="compensateBookHotelEvt" targetRef="undoBookHotel" />
      
      <association associationDirection="One" id="a2"  sourceRef="compensateBookFlightEvt" targetRef="undoBookFlight" />

    </transaction>
    
    <boundaryEvent attachedToRef="tx" id="catchCancelTx">
      <cancelEventDefinition id="calcel"/>      
    </boundaryEvent>
        
    <receiveTask id="afterCancellation" />
    <receiveTask id="afterSuccess" />
    
    <sequenceFlow sourceRef="catchCancelTx" targetRef="afterCancellation" />
    <sequenceFlow sourceRef="afterCancellation" targetRef="end" />
    
    <sequenceFlow sourceRef="tx" targetRef="afterSuccess" />
    <sequenceFlow sourceRef="afterSuccess" targetRef="end" />
    
    <endEvent id="end" />
    
  </process>

</definitions>
